package com.learner.common.exception;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * 抽象运行时异常,七巧所有异常都继承自此类,使得平台抛出的每一个异常都有code和msg信息,日后可根据日志快速定位问题,且REST接口的ExceptionHander可自动装配异常code和msg
 *
 * @author xiuwei
 * @date 2018/8/15
 */
@Slf4j
public class BaseRuntimeException extends RuntimeException {

    /**
     * 异常代码
     */
    protected Integer code;

    /**
     * 异常提示内容
     */
    protected String msg;

    public BaseRuntimeException() {
        super();
    }

    public BaseRuntimeException(String message) {
        super(message);
        this.msg = message;
        log.error(message);
    }

    public BaseRuntimeException(String message, Throwable cause) {
        super(message, cause);
        this.msg = message;
        log.error(message,cause);
    }

    public BaseRuntimeException(Throwable cause) {
        super(cause);
        this.msg = cause.getMessage();
        log.error(this.msg,cause);
    }

    protected BaseRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.msg = message;
        log.error(this.msg,cause);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
